package homework.entities;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Serializable;

import android.util.Log;

public class Tema implements Serializable {

	/**
	 * Generated serialVersionUID. 
	 */
	private static final long serialVersionUID = 8802958253598935554L;
	
	
	private String displayName;
	private String title;
	private String subject;
	private String deadline;
	private String notes;
	private File file;
	
	public Tema(){
		
	}
	
	public Tema(String displayName){
		
		this.displayName = displayName;
	}
	
	public Tema(String displayName, String title){
		
		this.displayName = displayName;
		this.title = title;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getDeadline() {
		return deadline;
	}

	public void setDeadline(String deadline) {
		this.deadline = deadline;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	@Override
	public String toString(){
		
		String toPrint = new String();
		
		
		String property = this.displayName;
		if(property.equals("")){
			toPrint += "-";
		}else if(property.contains("$")){
			String[] aux = property.split("$");
			property = "";
			for(int i = 0; i < aux.length; i++){
				property += aux[i];
			}
			toPrint += property;
		}else{
			toPrint += property;
		}
		
		toPrint+="$";
		
		property = this.title;
		if(property.equals("")){
			toPrint += "-";
		}else if(property.contains("$")){
			String[] aux = property.split("$");
			property = "";
			for(int i = 0; i < aux.length; i++){
				property += aux[i];
			}
			toPrint += property;
		}else{
			toPrint += property;
		}
		
		toPrint+="$";
		
		property = this.subject;
		if(property.equals("")){
			toPrint += "-";
		}else if(property.contains("$")){
			String[] aux = property.split("$");
			property = "";
			for(int i = 0; i < aux.length; i++){
				property += aux[i];
			}
			toPrint += property;
		}else{
			toPrint += property;
		}
		
		toPrint+="$";
		
		property = this.deadline;
		if(property.equals("")){
			toPrint += "-";
		}else if(property.contains("$")){
			String[] aux = property.split("$");
			property = "";
			for(int i = 0; i < aux.length; i++){
				property += aux[i];
			}
			toPrint += property;
		}else{
			toPrint += property;
		}
		
		toPrint+="$";
		
		property = this.notes;
		if(property.equals("")){
			toPrint += "-";
		}else if(property.contains("$")){
			String[] aux = property.split("$");
			property = "";
			for(int i = 0; i < aux.length; i++){
				property += aux[i];
			}
			toPrint += property;
		}else{
			toPrint += property;
		}
		
		toPrint += "$";
		toPrint += "\n";
		
		return toPrint;
	}
	
	
	public void print(){
		
		try{
			File myFile = new File(Constants.TEMA_SAVE_FILE);
			//myFile.createNewFile();
			FileOutputStream fOut = new FileOutputStream(myFile);
			OutputStreamWriter myOutWriter = 
								new OutputStreamWriter(fOut);
		
			String toPrint = this.toString();
			
			myOutWriter.append(toPrint);
			Log.d("MyTAG", toPrint);
			myOutWriter.close();
			fOut.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
}
